Skip to content

Parser: Skip close tag search for tag names with no closing tags#1794

Merged
marcoroth merged 1 commit into
mainfrom
optimize-match-tags-close-tag-lookup
Jun 12, 2026
Merged

Parser: Skip close tag search for tag names with no closing tags#1794
marcoroth merged 1 commit into
mainfrom
optimize-match-tags-close-tag-lookup

Conversation

@marcoroth

Copy link
Copy Markdown
Owner

This pull request updates the match_tags post-processing pass which calls find_matching_close_tag for every open tag, scanning forward through all remaining nodes.

With many unclosed tags (e.g. 50,000 × <div>), this is O(n²), each open tag scans to the end finding nothing.

A first pass now collects which tag names have closing tags. Open tags whose name isn't in that set skip the scan entirely, reducing the pathological case from O(n²) to O(n).

For 50,000 unclosed tags this went from ~13s down to ~0.17s.

@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown
npx https://pkg.pr.new/@herb-tools/formatter@1794
npx https://pkg.pr.new/@herb-tools/language-server@1794
npx https://pkg.pr.new/@herb-tools/linter@1794

commit: 78f73dd

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit 78f73dd


✅ Preview deployment has been cleaned up.

@github-actions github-actions Bot requested a deployment to herb-tools (Preview) June 12, 2026 14:24 Abandoned
@marcoroth marcoroth merged commit a6f1c3d into main Jun 12, 2026
38 of 39 checks passed
@marcoroth marcoroth deleted the optimize-match-tags-close-tag-lookup branch June 12, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant